﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AddDrug : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtnQk_Click(object sender, EventArgs e)
    {
        this.TxtID.Text = "";
        this.TxtComName.Text = "";
        this.TxtName.Text = "";
        this.TxtInfo.Text = "";
        this.TxtCountry.Text = "";
        this.TxtProducearea.Text = "";
        this.TxtSpec.Text = "";
        this.TxtAuthorizeSN.Text = "";
    }

    protected void BtnTj_Click(object sender, EventArgs e)
    {
        string sql = string.Format("select count(*) from DrugDict where DrugID='{0}'",this.TxtID.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        string DropTypeID = this.DropType.SelectedValue.ToString();
        if (n == 0)
        {
            if (this.TxtID.Text != "" && this.TxtName.Text != "" && this.TxtComName.Text !="" && this.TxtProducearea.Text !="" && this.TxtAuthorizeSN.Text !="")
            {
                string insertsql = string.Format("insert into DrugDict (DrugID,ComName,Name,DrupTypeID,Priceinfo,Spec,IsspecialManage,InsuranceType,Isimport,Country,Producearea,AuthorizeSN) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}') ", this.TxtID.Text, this.TxtComName.Text, this.TxtName.Text, DropTypeID, this.TxtInfo.Text,this.TxtSpec.Text,this.DropManage.SelectedValue,this.DropInsurance.SelectedValue,this.DropIsimport.SelectedValue,this.TxtCountry.Text,this.TxtProducearea.Text,this.TxtAuthorizeSN.Text);
                DBHelper.GetNonQuery(insertsql);
                Response.Write("<script> alert('药品添加成功!') </script>");
                this.TxtID.Text = "";
                this.TxtComName.Text = "";
                this.TxtName.Text = "";
                this.TxtInfo.Text = "";
                this.TxtCountry.Text = "";
                this.TxtProducearea.Text = "";
                this.TxtSpec.Text = "";
                this.TxtAuthorizeSN.Text = "";
            }
            else
            {
                Response.Write("<script> alert('添加失败,信息不能为空!') </script>");
            }
        }
        else
        {
            Response.Write("<script> alert('添加失败，请输入正确的信息!') </script>");
            this.TxtID.Text = "";
            this.TxtComName.Text = "";
            this.TxtName.Text = "";
            this.TxtInfo.Text = "";
            this.TxtCountry.Text = "";
            this.TxtProducearea.Text = "";
            this.TxtSpec.Text = "";
            this.TxtAuthorizeSN.Text = "";
        }
    }

    protected void TxtID_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from DrugDict where DrugID='{0}'", this.TxtID.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n != 0)
        {
            lblTs.Text = "药品编号已存在。";
        }
        else
        {
            lblTs.Text = "";
        }
    }

    protected void DropIsimport_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DropIsimport.SelectedIndex==1)
        {
            this.TxtCountry.Enabled = true;
        }
        else
        {
            this.TxtCountry.Enabled = false;
        }
    }
}